<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>移动照片</title>
    <link rel="stylesheet" href="${ctxStatic}/layui-v2.2.45/layui/css/layui.css">
    <script type="text/javascript" src='${ctxStatic}/jquery/jquery-2.1.4.min.js'></script>
    <script type="text/javascript" src="${ctxStatic}/layui-v2.2.45/layui/layui.js"></script>
    <script type="text/javascript" src="${ctx}/script/common/util.js"></script>

    <style type="text/css">
        li {
            border: 1px solid #ececec;
            display: inline-block;
            padding-left: 20px;
            padding-right: 20px;
            margin-right: 10px;
            margin-bottom: 10px;
            height: 35px;
            line-height: 35px;
            height: 35px;
        }

        li:hover {
            cursor: pointer;
        }

        li.checked {
            background-color: #cfb31b;
            color: white;
        }
    </style>
</head>
<body>

<div style="padding: 10px;">
    <ul>
        <li class="li-tag" style="background-color: lightgray" onclick="addAlbum('${photosId}')">+创建相册</li>
        <li class="li-tag li-tag-check" data-id="0">全部</li>
        <c:forEach var="tag" items="${tags}">
            <c:if test="${tag.id != tagId}">
                <li class="li-tag li-tag-check" data-id="${tag.id}">${tag.name}</li>
            </c:if>
        </c:forEach>
    </ul>
</div>
</body>
<script>

    $(function () {
        layui.use('layer', function () {
            var layer = layui.layer;
        });

        $(".li-tag-check").click(function () {
            if (!$(this).hasClass("checked")) {
                $(this).addClass("checked");
            } else {
                $(this).removeClass("checked");
            }
        });
    });

    function doSubmit(imgIds, tagId) {
        var array = new Array();
        $("li.checked").each(function (index, ele) {
            var id = $(ele).attr("data-id");
            array.push(id);
        });
        if (array.length < 1) {
            util.layerMsgError("请选择相册");
            return false;
        }
        var tagIds = array.join(",");
        $.post('${ctx}/photo/imgInfo/moveImg.do', {
            imgIds: imgIds,
            tagIds: tagIds,
            tagId: tagId
        }, function (ret) {
            if (ret.success) {
                util.layerMsgSuccess('移动成功', function () {
                    top.location.reload();
                });
            } else {
                util.layerMsgError(ret.description);
            }
        });
    }

    function addAlbum(photosId) {
        openDialog('创建分类', '${ctx}/photo/album/addAlbum.do?photosId=' + photosId, '436px', '239px', '', window);
    }

    function openDialog(title, url, width, height, cb, target) {
        var index = top.layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }
            },
            success: function () {
                $(':focus').blur();
            },
            cancel: function (index) {
            }
        });
    }

</script>
</html>